{extend name="layout:base" /}

{block name="style"}
    <link rel="stylesheet" href="__STATIC__/kindeditor/themes/default/default.css"/>
    <script charset="utf-8" src="__STATIC__/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="__STATIC__/kindeditor/lang/zh-CN.js"></script>
{/block}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-row layui-col-space10 layui-form-item">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">父栏目：</label>
                        <div class="layui-input-block">
                            <select name="pid"  lay-filter="pid">
                                <option value="0">顶级栏目</option>
                                {volist name="category_list" id="vo"}
                                <option value="{$vo.id}">{$vo.title}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">栏目名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item layui-hide">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">类型：</label>
                        <div class="layui-input-block">
                            <select name="type" lay-filter="category_type">
                                <option value="1">栏目</option>
                                <option value="2">单页</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row layui-col-space10 layui-form-item activeBox" style="display: none">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">图片：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="image" id="imageurl" value="" autocomplete="off" class="layui-input"/>
                        </div>
                        <input type="button" id="btnImgUpload" value="上传图片" class="layui-btn"/>
                    </div>
                </div>
                <div class="layui-form-item activeBox" style="display: none">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            预览图：
                            <div id="imageView">
                            </div>
                        </blockquote>
                    </div>
                </div>


                <div class="layui-row layui-col-space10 layui-form-item activeBox" style="display: none">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">简介：</label>
                        <div class="layui-input-block">
                            <textarea name="description" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item layui-hide">
                    <div class="layui-col-lg12">
                        <label class="layui-form-label">内容：</label>
                        <div class="layui-input-block">
                            <textarea name="content" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="btnAdd">保存</button>
                            <a class="layui-btn layui-btn-primary" href="javascript:parent.location.reload();">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}


{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: '/lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form', 'element', 'upload'], function () {
        var $ = layui.$,
            layer=layui.layer,
            form = layui.form;

        form.on('select(pid)', function(data){
            var id=data.value;
            if(id==8){
                $('.activeBox').show();
            }else{
                $('.activeBox').hide();
            }
        });


        form.on('submit(btnAdd)', function (data) {
            data.field.content = editor.html();
            console.log(data.field);

            $.post("{:url('/Admin/Category/add')}", data.field, function (result) {
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 6, time: 1000}, function () {
                        // parent.location.reload();

                        // window.parent.location.reload();//刷新父页面
                        // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        // parent.layer.close(index);
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });

            return false;

        });
    });
</script>
{/block}